package com.tuanzhang.mall.goods.domain.valueobj;

import com.tuanzhang.mall.seller.types.exception.ApiException;
import lombok.Getter;

/**
 * 类功能描述
 *
 * @author wangyl
 * @date 2025/6/17
 */
@Getter
public class Inventory {

    private Integer quantity;

    private Inventory(int quantity) {
        if (quantity < 0) {
            throw new ApiException("库存数量不能小于0");
        }
        this.quantity = quantity;
    }

    public static Inventory getQuantity(int quantity) {
        return new Inventory(quantity);
    }

    public void reduce(int quantity) {
        if (this.quantity < quantity) {
            throw new ApiException("库存数量不足");
        }
        this.quantity -= quantity;
    }

    public void add(int quantity) {
        this.quantity += quantity;
    }
}
